﻿Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.Collections.Generic
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Imports System.Data.Common
Public Class Reasons
#Region "Constants"
    Protected Const _ReasonID As String = "ReasonID"
    Protected Const _ReasonName As String = "ReasonName"

#End Region
#Region "Private"
    Private intReasonID As Integer
    Private strReasonName As String
    Private Shared el As New errorLog
#End Region
#Region "Public"
    Public Property ReasonID() As Integer
        Get
            Return intReasonID
        End Get
        Set(ByVal value As Integer)
            intReasonID = value
        End Set
    End Property
    Public Property ReasonName() As String
        Get
            Return strReasonName
        End Get
        Set(ByVal value As String)

        End Set
    End Property
#End Region

    Public Function LoadReasonByReasonID() As Boolean

        Dim blReasonFound = False

        Dim db As Database = DbStoreFactory.CreateDatabase
        Dim cmd As DbCommand = DirectCast(Nothing, DbCommand)
        Dim reader As IDataReader = Nothing

        Try
            cmd = db.GetStoredProcCommand("GetReasonByReasonID")
            db.DiscoverParameters(cmd)
            cmd.Parameters("@intReasonID").Value = ReasonID

            reader = db.ExecuteReader(cmd)

            Do While (reader.Read)
                intReasonID = Convert.ToInt16(reader(_ReasonID))
                strReasonName = reader(_ReasonName).ToString
                blReasonFound = True
            Loop

        Catch ex As Exception
            el.CatchError(ex)
        Finally
            If Not (cmd Is Nothing) Then
                cmd.Dispose()
            End If
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
        Return blReasonFound
    End Function
    Public Function GetAllReasons() As DataTable
        Dim db As Database = DbStoreFactory.CreateDatabase
        Dim cmd As DbCommand = DirectCast(Nothing, DbCommand)
        Dim reader As IDataReader = Nothing

        Dim dt As DataTable = New DataTable()
        dt.Columns.Add(_ReasonID, GetType(Integer))
        dt.Columns.Add(_ReasonName, GetType(String))

        Try
            cmd = db.GetStoredProcCommand("GetAllrefReasons")
            db.DiscoverParameters(cmd)

            reader = db.ExecuteReader(cmd)
            Dim dr As DataRow

            Do While (reader.Read)
                intReasonID = Convert.ToInt16(reader(_ReasonID))
                strReasonName = reader(_ReasonName).ToString

                dr = dt.NewRow()
                dr(_ReasonID) = intReasonID
                dr(_ReasonName) = strReasonName
                dt.Rows.Add(dr)
            Loop

        Catch ex As Exception
            el.CatchError(ex)
        Finally
            If Not (cmd Is Nothing) Then
                cmd.Dispose()
            End If
            If Not (reader Is Nothing) Then
                reader.Close()
            End If
        End Try
        Return dt
    End Function
End Class
